package org.yang.order.food.service.impl;


import org.yang.order.food.common.Msg;
import org.yang.order.food.dao.OrderInfoMapper;
import org.yang.order.food.entity.OrderInfo;
import org.yang.order.food.service.OrderInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单详细服务实现
 * @author shichenyang
 * @email gyv12345@163.com
 * @date 2018/12/03
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OrderInfoServiceImpl implements OrderInfoService {
    @Resource
    private OrderInfoMapper orderInfoMapper;

    @Override
    public Msg addOrderInfo(OrderInfo orderInfo) {
        int i=  orderInfoMapper.insert(orderInfo);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("添加成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("添加失败");
        }
        return msg;
    }

    @Override
    public Msg updateOrderInfo(OrderInfo orderInfo) {
        int i= orderInfoMapper.updateByParam(orderInfo);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("修改成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @Override
    public Msg delOrderInfo(OrderInfo orderInfo) {
        int i=orderInfoMapper.del(orderInfo.getId());
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("删除成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("删除失败");
        }
        return msg;
    }

    @Override
    public PageInfo getOrderInfos(OrderInfo orderInfo, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<OrderInfo> orderInfos=orderInfoMapper.list(orderInfo);
        PageInfo info=new PageInfo(orderInfos);
        return info;
    }
}
